cmake_minimum_required(VERSION 3.10)

include(PythonPath.cmake)                                                   # 查找系统Python3各配置路径

include_directories(${PYTHON_INCLUDE_PATH})                                 # 将python include目录设置为包含目录

link_directories("${PROJECT_SOURCE_DIR}/GeoLeo")                            # 链接生成的PhysLeo库
link_directories(${PYTHON_LIB_PATH})                                        # 添加python链接库目录
link_libraries(GeoLeo ${PYTHON_LIB})                                        # 链接pythonxx库（只在windows下链接，其余情况不链接）

set(SRC_DIR "${PROJECT_SOURCE_DIR}/PyBind")                                 #设置待编译源文件目录
file(                                                                       #利用glob命令读取所有源文件list
    GLOB_RECURSE SRC_LIST 
    LIST_DIRECTORIES false
    CONFIGURE_DEPENDS
    "${SRC_DIR}/*.c*"
    "${SRC_DIR}/*.h*"
)
add_library(PyGeoLeo SHARED ${SRC_LIST})                                    #添加编译目标 动态链接库

foreach(SRC IN ITEMS ${SRC_LIST})                                           #为VS工程添加filter 方便查看文件结构目录
    get_filename_component(SRC_PATH "${SRC}" PATH)
    file(RELATIVE_PATH SRC_PATH_REL "${SRC_DIR}" "${SRC_PATH}")
    string(REPLACE "/" "\\" GROUP_PATH "${SRC_PATH_REL}")
    source_group("${GROUP_PATH}" FILES "${SRC}")
endforeach()

set_target_properties(PyGeoLeo PROPERTIES SUFFIX ${PYTHON_EXT_SUFFIX})      # 设置目标后缀名
set_target_properties(PyGeoLeo PROPERTIES PREFIX "")                        # 设置目标前缀名 这里一定要设置，否则在linux darwin上会因为动态链接库名字和python定义入口不一致出错

install(TARGETS PyGeoLeo DESTINATION ${PYTHON_SITE_PATH})                   # 将生成目标注入python site-package


